/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package management;

import entity.FeedBack;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.swing.JOptionPane;

/**
 *
 * @author Windows7
 */
public class ManagerFeedBack {

    public static String sql_FeedbackCus = "select Fb_Id,Fb_Cus, Fb_Admin,Fb_Status from Feedback ";
    public static String sqlTbl_FeedBackFull = "select * from Feedback";
    public static String sqlTbl_FeedBack = "select * from Feedback  order by (Fb_Status) asc";

    public static boolean addFeedBack( int IdCus,String Fb_Cus) {
        try {
            PreparedStatement ps;
            String sql = "insert into  Feedback ( Customer_Id,Fb_Cus) values ( '"+IdCus+"','"+Fb_Cus+"')";
            ps = MyConnection.getConnection().prepareStatement(sql);
            ps.executeUpdate();
            return true;
        } catch (Exception ex) {
            ex.printStackTrace();
            return false;
        }
    }

    public static boolean updateFeedBack(String getCus, String getStatus, int id) {
        // muon update toan bo cac truong thi cho update tra ve kieu doi tuong do.
        // muon update 1 so truong thi truyen vao no cac tham so cac truong muon update
        String sql = "update Feedback set Fb_Admin = '" + getCus + "', Fb_Status= '" + getStatus + "' where Fb_Id='" + id + "'";
        try {
            PreparedStatement ps = null;
            ps = MyConnection.getConnection().prepareStatement(sql);
            ps.executeUpdate();
            return true;
        } catch (SQLException ex) {
            ex.printStackTrace();
            return false;
        }
    }

    public static void deleteFeedBack(int getid) {
        String sql = "delete from Feedback where Fb_Id = '" + getid + "' ";
        Statement st;
        try {
            st = MyConnection.getConnection().createStatement();
            st.executeUpdate(sql);
            JOptionPane.showMessageDialog(null, "Delete feedback successful!");
        } catch (SQLException ex) {
            ex.printStackTrace();
            JOptionPane.showMessageDialog(null, "Delete feedback type error!");
        }
    }
//    public static FeedBack searchMenu(int Status) {
//        String sql = "select * from Feedback where Fb_Status = 0 ";
//        try {
//            PreparedStatement ps = MyConnection.getConnection().prepareStatement(sql);
//            ps.setString(1, Status);
//            ResultSet rs = ps.executeQuery();
//
//            if (rs.next()) {
//                FeedBack fb = new FeedBack();
//                fb.set(rs.getString("Product_Name"));
//                fb.setProduct_price(rs.getDouble("Product_price"));
//                return menu;
//            }
//        } catch (SQLException ex) {
//            ex.printStackTrace();
//        }
//        return null;
//    }
//    
}
